package cn.chinamobile.remote.assistance.mobile.communication;

import cn.chinamobile.remote.assistance.mobile.codec.RemoteAssistanceCodec;
import java.io.IOException;
import org.glassfish.grizzly.filterchain.FilterChainBuilder;
import org.glassfish.grizzly.filterchain.TransportFilter;
import org.glassfish.grizzly.nio.transport.TCPNIOTransport;
import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder;

public final class MobileServer {

    public static final String HOST = "localhost";
    public static final int PORT = 9098;

    public MobileServer() {
        FilterChainBuilder filterChainBuilder = FilterChainBuilder.stateless();
        filterChainBuilder.add(new TransportFilter());
        filterChainBuilder.add(new RemoteAssistanceCodec());
        filterChainBuilder.add(new CommunicationFilter());

        final TCPNIOTransport transport = TCPNIOTransportBuilder.newInstance().build();
        transport.setProcessor(filterChainBuilder.build());

        try {
            transport.bind(PORT);
            transport.start();
//            System.out.println("Press <enter> to exit...");
//            System.in.read();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
//            try {
//                transport.shutdownNow();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
        }
    }
}
